<template>
  <el-dialog :visible.sync="visible" width="1000px" top="52px" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog page" @open="open" @close="close" :append-to-body="true" :modal-append-to-body="true">
    <div style="position:relative;" v-if="isAdd">
      <el-button icon="el-icon-plus" style="position: absolute;top: -53px;right: 40px;" :type="'text'" @click="openAddDialog">周期会议创建</el-button>
    </div>
    <div style="position:relative;" v-if="!isAdd && meetSrc != '' && model.showqrcode">
      <el-button style="position: absolute;top: -53px;right: 40px;" :type="'text'" @click="viewImage(meetSrc)">会议二维码</el-button>
      <!--      <el-avatar shape="square" @click.stop="" style="position: absolute;top: -53px;right: 40px;" :size="100" :src="meetSrc"></el-avatar>-->
    </div>
    <div :id="viewerId"></div>
    <el-tabs class="tl-tabs" v-model="activeTab" type="card" @tab-click="tabClick">
      <el-tab-pane label="会议信息" name="basic">
        <div style="padding-left:30px;padding-bottom:10px">
          <el-row>
            <div class="square"></div>
            <label class="meetInfo">会议基本信息</label>
            <!--            <el-button type="text" @click="doQueryMeetRecord" v-if="model.state === 1 && (model.record === true || model.audio === true)" class="viewMeetRecord_link">查看会议资料</el-button>-->
          </el-row>
        </div>
        <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="110px" :disabled="disableEditSubmit">
          <el-row>
            <el-col :span="24">
              <el-form-item label="会议主题" prop="name" :rules="rules.validateRequire">
                <el-input v-model="model.name" maxlength="200" placeholder="请输入会议主题"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="会议内容" prop="content">
                <el-input v-model="model.content" maxlength="200" type="textarea" :rows="2" placeholder="请输入会议内容"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="开始时间" prop="begintimeDate" :rules="rules.validateRequire">
                <el-date-picker v-model="model.begintimeDate" type="date" placeholder="开始时间" value-format="yyyy-MM-dd" :picker-options="expireTimeOption"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="" label-width="10px" prop="begintimeTime" :rules="rules.validateRequire">
                <el-time-select v-model="model.begintimeTime" placeholder="选择时间" editable :clearable="false" :picker-options="{
                    start: '00:00',
                    step: '00:05',
                    end: '24:00'
                  }">
                </el-time-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="结束时间" prop="endtimeDate" :rules="rules.validateRequire">
                <el-date-picker v-model="model.endtimeDate" type="date" placeholder="结束时间" value-format="yyyy-MM-dd" :picker-options="expireTimeOption"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="" label-width="10px" prop="endtimeTime" :rules="rules.validateRequire">
                <el-time-select v-model="model.endtimeTime" placeholder="选择时间" editable :picker-options="{
                    start: '00:00',
                    step: '00:05',
                    end: '24:00'
                  }">
                </el-time-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="会议类型" prop="meettypeid" :rules="rules.validateRequire">
                <el-cascader v-model="model.selectmeettypelist" :options="meetTypeList" style="width:100%" filterable @change="handleMeetTypeChange" clearable></el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="会议形式" prop="meetstyle" :rules="rules.validateRequire">
                <el-select v-model="model.meetstyle" filterable clearable>
                  <el-option v-for="item in codeModel.meetstyleList" :key="item.code" :label="item.name" :value="item.code" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="会议室" prop="meetroomid">
                <tl-ref-select-room v-model="model.meetroomid" :initDisplayData.sync="model.airlinecompany" :requireModel.sync="queryBoardItemModel" @open="initSelectMeetRoom" @updateRequire="updateRequire" :disabled="disableEditSubmit" sourceType="meetManage" @confirm="initPlace" @clearRoom="clearRoom"></tl-ref-select-room>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="自定义地点" prop="place">
                <el-input v-model="model.place" maxlength="100" placeholder="如果需要自定义会议地点，请在此输入"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="远程会议信息" prop="remotemeetinfo">
                <el-input v-model="model.remotemeetinfo" maxlength="1000" placeholder="如：腾讯会议，会议号：1021902912"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="会议标签" prop="keywords">
                <el-input v-model="model.keywords" maxlength="200" placeholder="会议关键字信息"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="参会人员" :rules="rules.rulesForInfo">
                <tl-ref-user v-model="model.usercode" :initDisplayData.sync="model.projectmanagername" :disabled="disableEditSubmit || disableSave" dataType="code" @confirm="projectmanagernameConfirm"></tl-ref-user>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="service.othervisiable">
            <el-col :span="24">
              <el-form-item label="其他" prop="otherservice" :rules="rules.validateRequire">
                <el-input v-model="model.otherservice" type="textarea" :rows="2" />
              </el-form-item>
            </el-col>
          </el-row>
          <tl-remind-config v-model="remindList"></tl-remind-config>
        </el-form>
      </el-tab-pane>

    </el-tabs>
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSubmitIssue" :loading="saveLoading" v-if="!disableEditSubmit">
        <svg-icon icon-class="send" />发布
      </el-button>
    </div>
    <!-- <tl-meet-record-edit ref="meetRecordEditForm" :sourceType="sourceType"></tl-meet-record-edit> -->
    <!--会议邀请-->
  </el-dialog>
</template>
<script>
/** mixins */
import { mixin_edit } from '@tapui/mixins/mixin_edit'
import { formatDate } from '@tapui/utils/date'
import { queryDataCode } from '@tapui/api/dataCode'
/** 子组件 */
// import tlMeetAgenda from '../meetAgenda/index'
// import tlMeetRecordEdit from '../meetRecord/edit'
// import tlRefSelectRoom from '../meetRoomManage/selectRoomIndex'
// import tlRefMeetType from '../meetTypeManage/refMeetType'
// import tlRefMulitUserSelect from '@/components/common/refMulitUserSelect'
// import tlRemindConfig from '@/components/common/remindConfig'
// import conflictList from '../../work/workSchedule/conflictList'
// import tlInvite from './invite'
// import peroidEdit from "../meetPeroidTask/edit"
// import tlRecordBasic from "../meetRecord/basicComp"
// import tlTaskManage from '../taskManage/index'
// import tlFileManage from '../fileManage/index'
// import uploadComp from "../meetRecord/uploadComp"
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
import axios from '@tapui/utils/request'
import Viewer from 'viewerjs'
/** VUE配置 */
export default {
  mixins: [mixin_edit],
  components: { },
  data() {
    return {
      moduleTitle: '会议',
      urlPrefix: '/meet/meetManage/',
      activeTab: 'basic',
      url: {
        add: '/meet/meetManage/save',
        edit: '/meet/meetManage/save',
        queryTeamList: 'base/teamInfo/list', // 查询团队
        queryVisibleTeamList: 'base/teamInfo/list?qry_visible=1', // 查询可见团队
        getMeetRecord: 'meet/record/queryRecordByMeet', // 得到会议资料
        publishMeet: 'meet/meetManage/publish', // 发布会议
        cancelMeet: 'meet/meetManage/cancel', // 取消会议
        queryUser: '/base/permissionManage/queryList', // 查询人员
        queryRemind: '/base/remindConfig/list', // 查询通知配置,
        queryMeetTypeList: '/meet/typeManage/queryTreeList',
        queryConflict: '/base/permissionManage/checkTimeConflict',
        judgeIsAttendUser: '/base/permissionManage/judgeIsAttendUser', // 查询是否为参会人员
        queryQRCode: '/cbo/attachment/queryAttachmentList', // 查询二维码
        download: '/cbo/attachment/download'
      },
      queryBoardItemModel: {
        begintime: '',
        endtime: '',
        count: 0
      },
      teamRefTitle: '团队选择',
      isQueryInitData: true,
      selectedMembers: {},
      isMemberSearch: false,
      activeNames: ['baseinfo', 'place', 'launchorg', 'notice'],
      users: {
        usernames: '',
        usercodes: '',
        deptnames: '',
        deptcodes: '',
        teamids: '',
        teamnames: '',
        roleids: '',
        rolenames: ''
      },
      remindTypeList: [],
      noticeTypeList: [],
      remindUnitTypeList: [],
      remindList: [], // 提醒,
      selectmeettypelist: [],
      meetTypeList: [],
      conflictList: [],
      selectedSourcelists: [],
      selectedServices: [],
      serviceList: [
        { code: 'welcomevisiable', name: '欢迎屏准备' },
        { code: 'signvisiable', name: '桌签准备' },
        { code: 'teavisiable', name: '茶歇准备' },
        { code: 'othervisiable', name: '其他' }
      ],
      service: {
        welcomevisiable: false,
        signvisiable: false,
        teavisiable: false,
        othervisiable: false
      },
      expireTimeOption: {
        disabledDate(date) {
          // 当天可选
          return date.getTime() < Date.now() - 24 * 60 * 60 * 1000
        }
      },
      inviteContent: '',
      isAttendUser: true,
      // 是否能上传会前资料
      canUpload: true,
      // 会议二维码路径
      meetSrc: '',
      imageViewer: null,
      viewerId: 'viewer',
      imageList: []
    }
  },
  props: {
    sourceType: {
      type: String,
      default: 'meetCreate'
    }
  },
  computed: {
    // 计算参会人员数目
    attendUserCount() {
      let count = 0
      for (let index in this.model.basesharelist) {
        let item = this.model.basesharelist[index]
        if (item.sharetype === 'attend' && item.allusernames) {
          count = item.allusernames.split(',').length
          break
        }
      }
      return count
    },
    // 控制是否显示会务配置
    showmainconfig() {
      return this.model && this.model.meetroomtype === 'company'
    },
    attendanceRule() {
      if (this.model.place.indexOf('报告厅') < 0) {
        return []
      } else {
        return this.rules.validateRequire
      }
    }
  },
  methods: {
    /** 查询编码 */
    doQueryCode() {
        getAction('http://172.20.3.106:7964/meet/meetManage/dataCodeList', {}).then((res) => {
          if (res.success) {
            this.codeModel = res.result
          } else {
            this.$tap.alert(res.message, 'warning')
          }
        })
    },
    loaded() {
       this.viewerId = 'viewer' + Math.floor(Math.random() * 100)
      // 新建会议时，页面加载完毕执行
      if (this.model.state === 2) {
        this.disableEditSubmit = true
      }
      // 设置初始页签为会议基本信息
      this.activeTab = 'basic'
      this.isMemberSearch = false
      this.remindId = -1
      if (!this.isAdd) {
        // 编辑
        // this.queryRemind()
        this.queryUser()
        // 判断是否是参会人员，从而判断是否显示会议议程tab标签
        this.judgeIsAttendUser()
        this.qryQRCode()
      } else {
        // 新增时设置默认值
        this.setDefaultValue()
      }
      this.processTime()
      // 判断当前会议已经开始，若开始则将canUpload置为false，若为新增则为true
      // if (!this.isAdd) {
      //   let begintime = new Date(this.model.begintime)
      //   let now = new Date()
      //   if (begintime > now) {
      //     this.canUpload = true
      //   } else {
      //     this.canUpload = false
      //   }
      // }
      this.setRoomConfigData()
    },
    // 处理会务配置数据
    setRoomConfigData() {
      // 将会议室配置转成数组类型
      if (this.model.sourcelist) {
        this.selectedSourcelists = this.model.sourcelist.split(',')
      } else {
        this.selectedSourcelists = []
      }
      // 会议服务
      this.selectedServices = []
      if (this.model.welcomeinfo) {
        this.selectedServices.push('welcomevisiable')
      }
      if (this.model.signinfo) {
        this.selectedServices.push('signvisiable')
      }
      if (this.model.teainfo) {
        this.selectedServices.push('teavisiable')
      }
      if (this.model.otherservice) {
        this.selectedServices.push('othervisiable')
      }
      this.doSelectService()
    },
    doSelectService() {
      Object.keys(this.service).forEach(key => {
        if (this.selectedServices.includes(key)) {
          this.service[key] = true
        } else {
          this.service[key] = false
          if (key === 'welcomevisiable') {
            this.$set(this.model, 'welcomeinfo', '')
            this.$set(this.model, 'welcometime', '')
          }
          if (key === 'signvisiable') {
            this.$set(this.model, 'signinfo', '')
          }
          if (key === 'teavisiable') {
            this.$set(this.model, 'teainfo', '')
          }
          if (key === 'othervisiable') {
            this.$set(this.model, 'otherservice', '')
          }
        }
      })
    },
    // 处理时间拆分
    processTime() {
      // 时间拆分
      if (this.model.begintime) {
        let beginArr = this.model.begintime.split(' ')
        this.$set(this.model, 'begintimeDate', beginArr[0])
        this.$set(this.model, 'begintimeTime', beginArr[1].substring(0, 5))
      } else {
        this.$set(this.model, 'begintimeDate', '')
        this.$set(this.model, 'begintimeTime', '')
      }
      if (this.model.endtime) {
        let endArr = this.model.endtime.split(' ')
        this.$set(this.model, 'endtimeDate', endArr[0])
        this.$set(this.model, 'endtimeTime', endArr[1].substring(0, 5))
      } else {
        this.$set(this.model, 'endtimeDate', '')
        this.$set(this.model, 'endtimeTime', '')
      }
    },
    // 会议创建画面设置默认值
    setDefaultValue() {
      this.$set(this.model, 'enabled', 1)
      this.$set(this.model, 'sortcode', 0)
      this.$set(this.model, 'launchusercode', this.user.code)
      this.$set(this.model, 'launchusername', this.user.name)
      this.$set(this.model, 'usercode', this.user.code)
      this.$set(this.model, 'username', this.user.name)
      this.$set(this.model, 'telephone', this.user.mobile)
      this.$set(this.model, 'launchorgtype', 'dept')
      this.$set(this.model, 'launchorgindex', this.dept.code)
      this.$set(this.model, 'launchorgname', this.dept.fullname)
      // 会议形式设置默认值：线下(code为1)
      this.$set(this.model, 'meetstyle', '1')
      // 时间默认值
      if (!this.model.begintime) {
        let now = formatDate(new Date(), 'yyyy-MM-dd')
        this.$set(this.model, 'begintime', now + ' 09:00:00')
        this.$set(this.model, 'endtime', now + ' 11:00:00')
      }
      this.users = {
        usernames: this.user.name,
        usercodes: this.user.code,
        deptnames: '',
        deptcodes: '',
        teamids: '',
        teamnames: '',
        roleids: '',
        rolenames: ''
      }
      // 默认
      this.remindList = [
        {
          id: 0,
          remindtype: '1',
          noticetype: 'app',
          unit: '1',
          value: 1,
          timeValue: '09:00:00'
        }
      ]
    },
    // tab切换
    tabClick(tab) {
      let tabName = tab.name
      if (!this.model.id && tabName !== 'basic') {
        this.$nextTick(_ => {
          this.activeTab = 'basic'
        })
        this.$tap.confirm('会议未创建，是否立即创建会议？').then(_ => {
          this.doCreate().then(_ => {
            this.activeTab = tabName
            if (tabName === 'meetAgenda') {
              this.$nextTick(_ => {
                this.$refs.meetAgenda.loadData({})
                if (this.sourceType !== 'meetCreate' || this.model.state === 2) {
                  this.$refs.meetAgenda.setDblClickActionType('view')
                } else {
                  this.$refs.meetAgenda.setDblClickActionType('edit')
                }
              })
            }
          })
        })
      } else {
        if (tabName === 'meetAgenda') {
          this.$nextTick(_ => {
            this.$refs.meetAgenda.loadData({})
            if (this.sourceType !== 'meetCreate' || this.model.state === 2) {
              this.$refs.meetAgenda.setDblClickActionType('view')
            } else {
              this.$refs.meetAgenda.setDblClickActionType('edit')
            }
          })
        } else if (tabName === 'taskManage') {
          this.$nextTick(_ => {
            this.$refs.taskManage.loadData({})
          })
        } else if (tabName === 'beforeminutes') {
          this.$nextTick(_ => {
            this.$refs.beforeAttachment.initData()
          })
        } else if (tabName === 'minutes') {
          this.$nextTick(_ => {
            this.$refs.attachment.initData()
          })
        } else if (tabName === 'file') {
          this.$nextTick(_ => {
            this.$refs.fileManage.loadData({})
          })
        } else if (tabName === 'recordBasic') {
          this.$set(this.$refs.recordBasic, 'id', this.model.recordid)
          this.$nextTick(_ => {
            this.$refs.recordBasic.open()
          })
        }
      }
    },
    /** 重写新建会议的方法，点击tab页创建会议时不需要关闭对话框 */
    doCreate() {
      let that = this
      return new Promise(function(re, rj) {
        that.$refs.form.validate(valid => {
          if (valid) {
            if (!that.beforeSubmit()) return
            that.saveLoading = true
            // 增加唯一单号
            postAction(that.url.add + '?billuid=' + that.uid, that.model)
              .then(res => {
                if (res.success) {
                  let meetType = that.model.selectmeettypelist
                  that.model = res.result
                  that.model.selectmeettypelist = meetType
                  // 处理时间
                  that.processTime()
                  that.isAdd = false
                  that.$emit('refresh')
                  re()
                } else {
                  rj()
                  that.$tap.alert(res.message, 'warning')
                }
                that.afterSubmit()
                that.saveLoading = false
              })
              .catch(err => {
                rj()
                that.saveLoading = false
              })
          } else {
            rj()
          }
        })
      })
    },
    /** 重写编辑，发请求获得数据 */
    queryData(id) {
      if (!this.url.load) {
        this.$tap.alert('请设置load地址!', 'warning')
        return
      }
      return getAction('http://172.20.3.106:7964/meet/meetManage/load', { id: id, operatetype: this.sourceType }).then(res => {
        if (res.success) {
          this.model = res.result
        } else {
          this.$tap.alert(res.message, 'warning')
        }
      })
    },
    /** 打开会议室列表，初始化 */
    initSelectMeetRoom() {
      this.$set(this.queryBoardItemModel, 'begintimeTime', `${this.model.begintimeTime}`)
      this.$set(this.queryBoardItemModel, 'endtimeTime', `${this.model.endtimeTime}`)
      this.$set(this.queryBoardItemModel, 'begintimeDate', `${this.model.begintimeDate}`)
      this.$set(this.queryBoardItemModel, 'endtimeDate', `${this.model.endtimeDate}`)
      this.$set(this.queryBoardItemModel, 'count', this.attendUserCount)
    },
    /** 更新会议室选择数据*/
    updateRequire(requireModel) {
      this.queryBoardItemModel = requireModel
      this.$set(this.model, 'begintimeTime', this.queryBoardItemModel.begintimeTime)
      this.$set(this.model, 'begintimeDate', this.queryBoardItemModel.begintimeDate)
      this.$set(this.model, 'endtimeTime', this.queryBoardItemModel.endtimeTime)
      this.$set(this.model, 'endtimeDate', this.queryBoardItemModel.endtimeDate)
      this.$set(this.model, 'meetroomtype', this.queryBoardItemModel.meetroomtype)
    },
    // 当切换组织类型时，清空组织信息
    clearOrgInfo() {
      this.$set(this.model, 'launchorgindex', '')
      this.$set(this.model, 'launchorgname', '')
    },
    // 会议室选择后，初始化自定义会议地点
    initPlace(item) {
      // 若选择的是公司级会议室则显示会务配置，否则隐藏，并清空数据
      if (item.type !== 'company') {
        this.hideAndClearRoomConfig()
      }
      this.$set(this.model, 'place', item.name + '(' + item.locationdesc + ')')
    },
    hideAndClearRoomConfig() {
      // 清空会议服务数据
      this.selectedServices = []
      this.doSelectService()
      this.$set(this.model, 'sourcelist', '')
      this.$set(this.model, 'preparerequest', '')
      this.$set(this.model, 'attendance', '')
    },
    // 清除会选择议室信息
    clearRoom() {
      this.$set(this.model, 'meetroomtype', '')
      this.$set(this.model, 'meetroomid', '')
      this.$set(this.model, 'airlinecompany', '')
      this.$set(this.model, 'place', '')
    },
    /** 提交前检查 */
    beforeSubmit() {
      this.model.begintime = `${this.model.begintimeDate} ${this.model.begintimeTime}`
      this.model.endtime = `${this.model.endtimeDate} ${this.model.endtimeTime}`
      let beginTime = new Date(this.model.begintime)
      let endTime = new Date(this.model.endtime)
      if (endTime <= beginTime) {
        this.$tap.alert('会议结束时间不能早于会议开始时间！')
        return false
      }
      // 人员组装
      if (this.users.usercodes.length === 0 && this.users.deptcodes.length === 0 && this.users.teamids.length === 0 && this.users.roleids.length === 0) {
        this.$tap.message('请选择参会人', 'error')
        return false
      }
      this.model.selectUsers = this.users
      // 提醒配置组装
      let remindList = []
      this.remindList.forEach((remind, index) => {
        remindList.push({
          id: remind.id,
          remindtype: remind.remindtype,
          unit: remind.unit,
          value: remind.remindtype === '1' ? remind.value : remind.timeValue,
          noticetype: remind.noticetype,
          sortcode: index
        })
      })
      this.model.remindList = remindList
      // 拼接会议配置，并赋值
      this.model.sourcelist = this.selectedSourcelists.join(',')
      return true
    },
    /** 重写新增提交，不关闭对话框 */
    doAdd() {
      this.saveLoading = true
      // 增加唯一单号
      postAction(this.url.add + '?billuid=' + this.uid, this.model)
        .then(res => {
          if (res.success) {
            this.$tap.message('添加成功', 'success')
            let meetType = this.model.selectmeettypelist
            this.model = res.result
            this.model.selectmeettypelist = meetType
            // 处理时间
            this.processTime()
            this.isAdd = false
            this.$emit('refresh')
          } else {
            this.$tap.alert(res.message, 'warning')
          }
          this.afterSubmit()
          this.saveLoading = false
        })
        .catch(err => {
          this.saveLoading = false
        })
    },
    /** 重写编辑提交，不关闭对话框 */
    doEdit() {
      this.saveLoading = true
      putAction(this.url.edit, this.model)
        .then(res => {
          if (res.success) {
            this.$tap.message(res.message, 'success')
            this.$emit('refresh')
          } else {
            this.$tap.alert(res.message, 'warning')
          }
          this.afterSubmit()
          this.saveLoading = false
        })
        .catch(err => {
          this.saveLoading = false
        })
    },

    // 执行发布会议
    doSubmitIssue() {
      let that = this
      this.$refs.form.validate(valid => {
        if (valid) {
          if (!this.beforeSubmit()) {
            that.saveLoading = false
            return
          }
          this.$tap
            .confirm('是否发布时间为(' + this.model.begintime + '至' + this.model.endtime + ')的会议？发布后会通知参会人！')
            .then(_ => {
              this.saveLoading = true
              this.checkConflict()
            })
            .catch(_ => {
              this.saveLoading = false
            })
        } else {
          return false
        }
      })
    },
    // 取消会议室审批，将会议状态置为作废
    doCancelMeet() {
      let that = this
      this.$tap
        .confirm('是否将会议作废？作废后不可恢复！')
        .then(_ => {
          that.saveLoading = true
          postAction(this.url.cancelMeet, this.model).then(res => {
            if (res.success) {
              this.disableEditSubmit = true
              this.$tap.message(res.message, 'success')
              this.$emit('refresh')
              that.saveLoading = false
              this.visible = false
            } else {
              this.$tap.alert('作废失败', 'warning')
              that.saveLoading = false
            }
          })
        })
        .catch(_ => {
          that.saveLoading = false
        })
    },
    /** 会议资料 */
    doQueryMeetRecord() {
      getAction(this.url.getMeetRecord, { qry_meetid: this.model.id })
        .then(res => {
          if (res.success) {
            this.$refs.meetRecordEditForm.id = res.result.id
            this.$refs.meetRecordEditForm.visible = true
            this.$refs.meetRecordEditForm.isAdd = false
            if (this.sourceType === 'meetCreate') {
              this.$refs.meetRecordEditForm.disableEditSubmit = false
              this.$refs.meetRecordEditForm.sourceType = 'meetCreate'
            } else {
              this.$refs.meetRecordEditForm.sourceType = 'meetSearch'
              this.$refs.meetRecordEditForm.disableEditSubmit = true
            }
          } else {
            this.$tap.alert(res.message, 'warning')
          }
        })
        .catch(err => {
          this.saveLoading = false
        })
    },
    // // 查询提醒配置
    // queryRemind() {
    //   getAction('', { qry_sourcetype: 'MeetManage', qry_sourceid: this.model.id }).then(res => {
    //     if (res.success) {
    //       this.remindList = []
    //       res.result.dataList.forEach(m => {
    //         this.remindList.push({
    //           id: m.id,
    //           remindtype: m.remindtype,
    //           noticetype: m.noticetype,
    //           unit: m.unit,
    //           value: m.remindtype === '1' ? m.value : '1',
    //           timeValue: m.remindtype === '2' ? m.value : '09:00:00'
    //         })
    //       })
    //     }
    //   })
    //   // 保存旧
    //   this.oldRemindList = JSON.parse(JSON.stringify(this.remindList))
    // },
    // 查询人员
    queryUser() {
      getAction('http://172.20.3.106:7964/base/permissionManage/queryList', { qry_sourcetype: 'MeetManage', qry_sourceid: this.model.id }).then(res => {
        if (res.success) {
          this.users = {
            usernames: '',
            usercodes: '',
            deptnames: '',
            deptcodes: '',
            teamids: '',
            teamnames: '',
            roleids: '',
            rolenames: ''
          }
          res.result.forEach(m => {
            if (m.sharetype === '5') {
              this.users.usernames = m.shareobjectsdesc
              this.users.usercodes = m.shareobjects
            } else if (m.sharetype === '1') {
              this.users.deptnames = m.shareobjectsdesc
              this.users.deptcodes = m.shareobjects
            } else if (m.sharetype === '3') {
              this.users.rolenames = m.shareobjectsdesc
              this.users.roleids = m.shareobjects
            } else if (m.sharetype === '2') {
              this.users.teamnames = m.shareobjectsdesc
              this.users.teamids = m.shareobjects
            }
          })
        }
      })
      this.oldUsers = JSON.parse(JSON.stringify(this.users))
    },
    handleMeetTypeChange(value) {
      if (typeof value !== 'undefined') {
        this.model.meettypeid = value[value.length - 1]
      }
    },
    // 日程冲突检测
    checkConflict() {
      let param = {
        ...this.users,
        begintime: this.model.begintime,
        endtime: this.model.endtime,
        sourceid: this.model.id,
        sourcetype: 'MeetManage'
      }
      getAction(this.url.queryConflict, param)
        .then(res => {
          if (res.success) {
            this.conflictList = res.result
            if (res.result.length > 0) {
              this.$confirm('所选会议参会人中存在日程时间冲突，是否继续发布？', '提示', {
                confirmButtonText: '查看冲突',
                cancelButtonText: '忽略冲突继续发布',
                type: 'warning'
              })
                .then(_ => {
                  // 查看冲突
                  this.$refs.conflictList.visible = true
                  this.saveLoading = false
                })
                .catch(_ => {
                  // 忽略继续保存
                  this.publishMeet()
                })
            } else {
              // 没有冲突
              this.publishMeet()
            }
          } else {
            // 调用接口出错了
            this.conflictList = []
            this.publishMeet()
          }
        })
        .catch(_ => {
          // 调用接口出错了
          this.conflictList = []
          this.publishMeet()
        })
    },
    // 发布会议
    publishMeet() {
      this.saveLoading = true
      postAction(this.url.publishMeet, this.model).then(res => {
        if (res.success) {
          this.$tap.message(res.message, 'success')
          this.$emit('refresh')
          this.visible = false
          this.saveLoading = false
        } else {
          this.$tap.alert(res.message, 'warning')
          this.saveLoading = false
        }
      })
    },
    /** 复制邀请 */
    doCopyInvite() {
      this.inviteContent = '会议主题: ' + this.model.name + '\r\n\r'
      this.inviteContent += '会议时间: ' + this.model.begintime + '至' + this.model.endtime + '\r\n\r'
      this.inviteContent += '会议号: ' + this.model.meetnum + '\r\n\r'
      this.inviteContent += '打开鼎信管理平台app-会议管理-输入会议号即可加入会议'
      this.$refs.inviteForm.open()
    },
    /** 查询用户是否为该会议的参会人员 */
    judgeIsAttendUser() {
      getAction('http://172.20.3.106:7964/base/permissionManage/judgeIsAttendUser', { qry_sourcetype: 'MeetManage', qry_sourceid: this.model.id }).then(res => {
        if (res.success) {
          this.isAttendUser = res.result.isAttendUser
        }
      })
    },
    /** 打开编辑周期会议对话框 */
    openAddDialog() {
      this.visible = false
      this.$refs.peroidEdit.isAdd = true
      this.$refs.peroidEdit.visible = true
      this.$refs.peroidEdit.disableEditSubmit = false
    },
    /** 查询会议的二维码 */
    qryQRCode() {
      getAction(this.url.queryQRCode, { qry_sourceType: 'meetJoin', qry_sourceId: this.model.meetnum }).then((res) => {
        if (res.success) {
          if (res.result && res.result.length > 0) {
            let attachmentId = res.result[0].id
            axios({
              url: this.url.download,
              method: 'post',
              data: { attachmentId: attachmentId },
              responseType: 'arraybuffer'
            }).then((response) => {
              this.meetSrc = 'data:image/png;base64,' + this.$tap.util.bufferToBase64(response)
              this.imageList.push(this.meetSrc)
            })
          }
        } else {
          this.$tap.alert(res.message, 'warning')
        }
      })
    },
    close() {
      this.meetSrc = ""
      this.imageList = []
    },
    viewImage(src) {
      // for (let item of this.imageList) {
      //   if (!item.ex_base64) this.asyncDisplay(item)
      // }
      if (!this.imageViewer) {
        this.imageViewer = new Viewer(document.getElementById(this.viewerId), {
          url(str) {
            return str
          },
          title: [
            1,
            "参会二维码"
          ]
        })
      }
      this.imageViewer.options.zIndex = 666666
      this.imageViewer.images = this.imageList
      this.imageViewer.length = this.imageViewer.images.length
      let idx = this.imageList.findIndex((item) => item === src)
      this.imageViewer.index = idx
      this.imageViewer.show()
    }
  },
  created() {
    // getAction('http://172.20.3.106:7964/meet/dataCodeList', { itemCodes: 'BaseRemindType,BaseNoticeType,BaseRemindUnitType' }).then(res => {
    //   debugger
    //   if (res.success) {
    //   this.remindTypeList = res.result.BaseRemindType
    //   this.noticeTypeList = res.result.BaseNoticeType
    //   this.remindUnitTypeList = res.result.BaseRemindUnitType
    //   }
    // })
    /** 查询会议类型树 */
    getAction('http://172.20.3.106:7964/meet/typeManage/queryTreeList', { isAddRoot: false }).then(res => {
      if (res.success) {
        let reg = new RegExp('id', 'g') // g代表全部
        this.meetTypeList = JSON.parse(JSON.stringify(res.result.dataList).replace(reg, 'value'))
      }
    })
  }
}
</script>

<style scoped lang="scss">
.tag-container {
  .el-tag {
    margin-right: 5px;
  }
}
.color-block {
  display: inline-block;
  height: 15px;
  width: 15px;
}
.input-with-select {
  .el-select {
    width: 80px;
  }
}
</style>
<style lang="scss">
.page .share-content {
  margin-left: 15px;
  margin-bottom: 5px;
}
.page .label-content {
  color: #409eff;
}
.page .el-collapse-item__header {
  color: blue;
}

.page .el-divider__text {
  color: blue;
}
.page .el-row {
  margin-right: 40px;
}
.page .el-divider--horizontal {
  margin: 14px 0;
}
.page .meetTitle {
  padding-top: 5px;
  padding-bottom: 10px;
  padding-left: 30px;
}
.page .meetInfo {
  color: black;
  font-size: 14px;
  font-weight: bold !important;
  vertical-align: middle;
}
.page .el-scrollbar__wrap {
  overflow-x: hidden;
}
.page .viewMeetRecord_link {
  padding: 0;
}
</style>
